import java.util.Scanner;

public class Search {
    private int vexNum;
    private VNode[] vexs;
    private ArcNode[][] arcs;

    public Search(int vexNum, VNode[] vexs, ArcNode[][] arcs){
        this.vexNum = vexNum;
        this.vexs = vexs;
        this.arcs = arcs;
    }

    public void Search_main(){
        Main m = new Main();
        System.out.println("————————————————————查询系统————————————————————");
        System.out.println("请选择查询条件:");
        System.out.println("（1）以起点站查询。");
        System.out.println("（2）以起飞时间查询。");
        System.out.println("（3）以票价查询。");
        System.out.println("（0）返回到主菜单。");
        System.out.println("——————————————————————————————————————————————");
        Scanner sc = new Scanner(System.in);
        int i = sc.nextInt();
        switch (i){
            case 1:
                Search_start();
                break;
            case 2:
                Search_time();
                break;
            case 3:
                Search_fares();
                break;
            case 0:
                m.menu();
            default:
                System.out.println("请输入1、2、3、0进行选择。");
                break;
        }
    }

    public void Search_start(){
        Main m = new Main();
        int n = 0;
        System.out.println("——————————————————起点站查询————————————————————");
        System.out.println("请输入起点站进行查询。");
        Scanner sc = new Scanner(System.in);
        String t = sc.next();
        ArcNode[][] a = new ArcNode[10][10];
        System.out.println("查询结果:");
        for (int i = 0;i<vexNum;i++){
            for (int j = 0;j<vexNum;j++){
                if (arcs[i][j] != null){
                    if (t.equals(arcs[i][j].adjVex.site)){
                        a[i][j] = arcs[i][j];
                        System.out.println(arcs[i][j]);
                        n++;
                    }
                }
            }
        }
        if (n == 0)
            System.out.println("无查询结果。");
        arcs = a;
        System.out.println("——————————————————————————————————————————————");
        System.out.println("是否继续查询？");
        System.out.println("（1）继续查询\t\t（2）结束查询");
        Scanner sc2 = new Scanner(System.in);
        int q = sc.nextInt();
        switch (q) {
            case 1:
                Search_main();
                break;
            case 2:
                m.menu();
                break;
            default:
                System.out.println("请输入1、2进行选择。");
                break;
        }
    }

    public void Search_time(){
        Main m = new Main();
        int n = 0;
        System.out.println("——————————————————起飞时间查询——————————————————");
        System.out.println("请输入起飞时间进行查询。");
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        ArcNode[][] a = new ArcNode[10][10];
        System.out.println("查询结果:");
        for (int i = 0;i<vexNum;i++){
            for (int j = 0;j<vexNum;j++){
                if (arcs[i][j] != null){
                    if (t == arcs[i][j].data.Time){
                        a[i][j] = arcs[i][j];
                        System.out.println(arcs[i][j]);
                        n++;
                    }
                }
            }
        }
        if (n == 0)
            System.out.println("无查询结果。");
        arcs = a;
        System.out.println("——————————————————————————————————————————————");
        System.out.println("是否继续查询？");
        System.out.println("（1）继续查询\t\t（2）结束查询");
        Scanner sc2 = new Scanner(System.in);
        int q = sc.nextInt();
        switch (q) {
            case 1:
                Search_main();
                break;
            case 2:
                m.menu();
                break;
            default:
                System.out.println("请输入1、2进行选择。");
                break;
        }
    }

    public void Search_fares(){
        Main m = new Main();
        int n = 0;
        System.out.println("————————————————————票价查询————————————————————");
        System.out.println("请输入票价进行查询。");
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        ArcNode[][] a = new ArcNode[10][10];
        System.out.println("查询结果:");
        for (int i = 0;i<vexNum;i++){
            for (int j = 0;j<vexNum;j++){
                if (arcs[i][j] != null){
                    if (t >= arcs[i][j].value){
                        a[i][j] = arcs[i][j];
                        System.out.println(arcs[i][j]);
                        n++;
                    }
                }
            }
        }
        if (n == 0)
            System.out.println("无查询结果。");
        arcs = a;
        System.out.println("——————————————————————————————————————————————");
        System.out.println("是否继续查询？");
        System.out.println("（1）继续查询\t\t（2）结束查询");
        Scanner sc2 = new Scanner(System.in);
        int q = sc.nextInt();
        switch (q) {
            case 1:
                Search_main();
                break;
            case 2:
                m.menu();
                break;
            default:
                System.out.println("请输入1、2进行选择。");
                break;
        }
    }
}
